<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="js/mui.js"></script>
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/header.css" />

		<style>
			#btn_login {
				background-color: #1aad19;
			}
			
			#btn_login:active {
				background-color: #128e12;
			}
		</style>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title" style="position: fixed;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left title-color"></a>
			<h1 class="mui-title title-color"><b id="chatting-nickname">扫码登录</b></h1>
		</header>

		<div class="mui-content">
			<div style="text-align: center;margin-top: 180px;">
				<img  src="image/wx_login.png" style="width: 30%;height:30%;" />
			</div>
			
			<br />
			<div style="text-align: center;margin-top: 140px;">
				<button id="btn_login" type="button" class="mui-btn mui-btn-block" style="color: white;width: 80%;border-radius:10px;display: inline;padding: 12px 0">登录</button>
				<button id="btn_cancel" type="button" class="mui-btn mui-btn-block" style="margin-top:10px;width: 80%;border-radius:10px;display: inline;padding: 12px 0">取消</button>
			</div>

		</div>

		<script type="application/javascript" src="js/app.js"></script>
		<script type="text/javascript">
			mui.init();

			mui.plusReady(function() {
				// 绑定取消的函数
				var btn_cancel = document.getElementById("btn_cancel");
				btn_cancel.addEventListener("tap", function() {
					mui.openWindow({
						url: "index.html",
						id: "index.html"
					});
				});
				//绑定登录的函数
				var btn_login = document.getElementById("btn_login");
				btn_login.addEventListener("tap", function() {
					var userInfo = app.getUserGlobalInfo();

					// 获取上一个页面传入的对象，并且对本页面响应的dom赋值初始化
					var currentWebview = plus.webview.currentWebview();
					var qrcodeId = currentWebview.qrcodeId;

					plus.nativeUI.showWaiting("请稍后...");
					mui.ajax(app.serverUrl + "/qrcode/confirmLogin?qrCodeId=" + qrcodeId + "&userId=" + userInfo.id, {
						data: {},
						dataType: 'json', //服务器返回json格式数据
						type: 'get', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
							//服务器返回响应
							plus.nativeUI.closeWaiting();

							if(data.success) {
								app.showToast("登录成功", "success");

								mui.openWindow({
									url: "index.html",
									id: "index.html"
								});
							} else {
								app.showToast(data.msg, "error");
							}
						}
					});
				});
			});
		</script>
	</body>

</html>